#include <iostream>
using std::cout;
using std::endl;

struct FunctionObject{
    int operator()(){
        cout << "int operator()()" << endl;
        ++_cnt;
        return 1;
    }

    int operator()(int x,int y){
        cout << "int operator()()" << endl;
        ++_cnt;
        return x + y;
    }

    //第一个括号里不能放内容，因为表示的是对（）这个运算符进行重载
    FunctionObject & operator()(int x){
        cout << "FunctionObject & operator()(int)" << endl;
        ++_cnt;
        return *this;
    }
    int _cnt = 0;
};

int cnt = 0;
void test0(){
    ++cnt;
}

int main(void){
    test0();
    test0();
    test0();
    test0();
    cout << cnt << endl;

    FunctionObject fo;
    cout << fo() << endl;
    cout << fo(1,2) << endl;
    cout << fo(1)(1,2) << endl;
    //函数对象可以封装自己的数据成员，比如用_cnt记录状态
    cout << "_cnt:" << fo._cnt << endl;
    return 0;
}
